<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义指令</title>
</head>
<body>
    <div id="app">
        <div v-fontc="'green'">自定义指令定义字体颜色</div>
        <div v-fontc="'blue'">自定义指令定义字体颜色</div>
        <div v-fontc="'orange'">自定义指令定义字体颜色</div>
        <div v-fontc="color">自定义指令定义字体颜色</div>
        <button @click="color='blue'">改变颜色</button>
    </div>
</body>
<script src='../js/vue.js'></script>
<script>
    Vue.directive("fontc",{
        bind(el,binding){
            console.log("指令绑定到dom上的时候触发")
            el.style.color = binding.value
        },
        inserted(el){
            console.log("指令被插入到父节点的时候执行")
        },
        update(el,binding){
            console.log("组件更新")
            el.style.color = binding.value
        },
        componentUpdated(){
            console.log("组件更新完毕")
        },
    })
    let vm = new Vue({
        el: '#app',
        data: {
             color:"red"
        },
        methods: {}
    })
</script>
</html>